package api.homework.one;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**千位
 * @author lwj
 * @date 2025-03-10
 * @vesion 1.0.0
 */
public class MainTest01 {
    public static void main(String[] args) {
        // Callable 接口实现类对象
        SumCallable decade = new SumCallable(1,100);// 1-100的计算
        SumCallable hundreds = new SumCallable(101,900);// 101-900的计算
        SumCallable kilobit = new SumCallable(901,1000);// 901-1000的计算

        // 创建 FutureTask 对象，并设置 Callable
        FutureTask<Integer> futureTask1 = new FutureTask<>(decade);
        FutureTask<Integer> futureTask2 = new FutureTask<>(hundreds);
        FutureTask<Integer> futureTask3 = new FutureTask<>(kilobit);

        // 创建 Thread 对象
        Thread thread1 = new Thread(futureTask1);
        Thread thread2 = new Thread(futureTask2);
        Thread thread3 = new Thread(futureTask3);

        // 启动线程
        thread1.start();
        thread2.start();
        thread3.start();

        int sum = 0;// 获取总数
        // 获取结果集
        try {
            sum += futureTask1.get();
            sum += futureTask2.get();
            sum += futureTask3.get();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }

        System.out.println("1-1000的总数为："+sum);
    }
}
